package com.zhsj.OkeHomeConsumption.ui.fragment.minehome;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.orhanobut.hawk.Hawk;
import com.zhsj.OkeHomeConsumption.R;
import com.zhsj.OkeHomeConsumption.common.Constants;
import com.zhsj.OkeHomeConsumption.common.MyActivity;
import com.zhsj.OkeHomeConsumption.empty.FormalUserInfo;
import com.zhsj.OkeHomeConsumption.ui.activity.PayAmountActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.zhsj.OkeHomeConsumption.common.Constants.SHARED_PERFERENCE_USERINFO;

/**
 * author : Xingdx
 * <p>
 * time   : 2018/10/18
 * desc   : 保证金支付订单
 */
public final class SecurityDepositActivity extends MyActivity {

    @BindView(R.id.quankuan_che)
    CheckBox quankuanChe;
    @BindView(R.id.fenqi_che)
    CheckBox fenqiChe;
    @BindView(R.id.fenqizuidi_text)
    TextView fenqizuidiText;
    @BindView(R.id.lin_fenqin)
    LinearLayout linFenqin;
    @BindView(R.id.baozhengjin_text)
    TextView baozhengjinText;
    @BindView(R.id.lin_baozhengjin)
    LinearLayout linBaozhengjin;
    @BindView(R.id.submit_rel)
    RelativeLayout submitRel;
    @BindView(R.id.text)
    TextView text;

    //用户信息实体
    private FormalUserInfo userInfo = null;

    private String depositHigh;//最高保证金 ,
    private String depositLow;//最低保证金 ,
    private String depositRate;//每笔抽成比例 ,

    private String deposit = null;

    private String lifetype = "";

    @Override
    protected int getLayoutId() {
        return R.layout.activity_securitydeposit;
    }

    @Override
    protected int getTitleId() {
        return R.id.tb_copy_title;
    }

    @Override
    protected void initView() {
        userInfo = Hawk.get(Constants.SHARED_PERFERENCE_USERINFO);
    }

    @Override
    protected void initData() {
        depositHigh = getIntent().getStringExtra("depositHigh");
        depositLow = getIntent().getStringExtra("depositLow");
        depositRate = getIntent().getStringExtra("depositRate");
        if(userInfo.getLifeUserDTO().getLifeType()==0){
            lifetype = getIntent().getStringExtra("lifetype");
        }
        fenqiChe.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    quankuanChe.setChecked(false);
                    text.setText("首次缴纳金额");
                    fenqizuidiText.setText("￥"+depositLow);
                    linBaozhengjin.setVisibility(View.VISIBLE);
                    linFenqin.setVisibility(View.VISIBLE);
                    double dou1 = Double.parseDouble(depositHigh);
                    double dou2 = Double.parseDouble(depositLow);
                    deposit = depositLow;
                    baozhengjinText.setText("￥"+(dou1-dou2));
                }

            }
        });
        quankuanChe.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    fenqiChe.setChecked(false);
                    linFenqin.setVisibility(View.GONE);
                    text.setText("缴纳金额");
                    fenqizuidiText.setText("￥"+depositHigh);
                    deposit = depositHigh;
                    linBaozhengjin.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.submit_rel})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.submit_rel:
               if(deposit==null){
                   toast("请选择支付方式");
                   return;
               }
               if(userInfo.getLifeUserDTO().getLifeType()==0){

                   startActivity(new Intent(this, PayAmountActivity.class).putExtra("pay_flage", 0).putExtra("price", deposit)
                           .putExtra("usertype", lifetype));
               }else{
                   startActivity(new Intent(this, PayAmountActivity.class).putExtra("pay_flage", 0).putExtra("price", deposit)
                           .putExtra("usertype", String.valueOf(userInfo.getLifeUserDTO().getLifeType())));
               }



                break;
        }
    }
}